package threadTest;

// 线程插队,插队成功则插队的线程一定先执行
public class QueueJumping{
    public static void main(String[] args) throws InterruptedException {
        Son son = new Son();
        son.start();
        for (int i= 0;i<20;i++){
            System.out.println("我是主线程: "+Thread.currentThread().getName());
            if (i == 5){
                System.out.println("让子线程先执行...");
                son.join();
                System.out.println("子线程执行完毕，主线程继续执行...");
            }
        }

    }
}

class Son extends Thread{
    @Override
    public void run(){
        for (int i =0;i<20;i++){
            System.out.println("我是子线程:hello " + Thread.currentThread().getName());
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }

    }
}
